package com.tasks;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.model.Category;
import com.service.CategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ScheduledTasks {
    @Autowired
    CategoryService categoryService;
    private static final Logger log = LoggerFactory.getLogger(ScheduledTasks.class);

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    @Scheduled(fixedRate = 5000)
    public void reportCurrentTime() {
        Category category = categoryService.selectCategoryByPk(2);
        log.info("The time is now {}", dateFormat.format(new Date()));
        log.info("The category{}", category.getTitle());
    }
}